<?php
namespace app\mini\model;

use think\Model;
use traits\model\SoftDelete;

class Order extends Model {
    
     protected $autoWriteTimestamp = true;

    use SoftDelete;

    protected $deleteTime = 'delete_time';

    public function Team() {
        return $this->hasOne('team', 'id', 'initiator')->field('team_name');
    }

    /*
     * 查询企业上传项目信息
     * @param $where where
     * @param $field field
     * @author cpy(1442435897@qq.com)
     */
    public function getInfo($where,$field = '*') {
        $res = $this->field($field)->where($where)->find();
        return empty($res)?array():$res->toArray();
    }
    
    /*
     * 查询所有
     * @param $where where
     * @param $field field
     * @author cpy(1442435897@qq.com)
     */
    public function selectInfo($where,$field = '*') {
        $res = $this->field($field)->where($where)->select();
        return empty($res)?array():$res->toArray();
    }
    
    /*
     * 查询所有企业用户项目
     * @param $where where
     * @param $field field
     * @author cpy(1442435897@qq.com)
     */
    public function selectGroupInfo($where,$group,$field = '*') {
        $res = $this->field($field)->where($where)->group($group)->select();
        return empty($res)?array():$res->toArray();
    }
    
    /*
     * 联合查询所有企业用户项目
     * @param $where where
     * @param $field field
     * @author cpy(1442435897@qq.com)
     */
    public function selectJoinGroupInfo($where,$group,$field = '*') {
        $res = $this->alias('a')->join('member b','b.id=a.uid')->field($field)->where($where)->group($group)->select();
        return empty($res)?array():$res->toArray();
    }
    
    /*
     * 查询所有企业用户项目
     * @param $where where
     * @param $field field
     * @author cpy(1442435897@qq.com)
     */
    public function selectLimitInfo($where,$limit,$field = '*') {
        $res = $this->field($field)->where($where)->limit($limit)->select();
        return empty($res)?array():$res->toArray();
    }


    /**
  * 查询所有项目投资记录
  * @param $where where
  * @author hey_heyang(635870453@qq.com)
  */
    public function selectAllinvest() {
        $where['o.status'] = ['gt',1];
        $where['o.type'] = 1;
        $where['p.id'] = ['not in',[36,38,39,40]];
        $filed='sum(o.money) as money,p.project_name,p.picture';
        $res=$this->alias('o')
            ->join('project p','o.project_id=p.id')
            ->where($where)
            ->field($filed)
            ->group('o.project_id')
            ->order('p.id desc')
            ->select();
        return empty($res)?array():$res->toArray();
    }


    /**
     * 获取当日投资列表
     * @author hey_heyang(635870453@qq.com)
     */
    public function  getTodayOrderList(){
        $today_begin = strtotime('today');
        $today_end = strtotime('today')+86400;
        $where['o.status'] = ['gt',1];
        $where['o.type'] = 1;
        $where['o.create_time'] = ['between',$today_begin.','.$today_end];
        $where['p.id'] = ['not in',[36,38,39,40]];
        $filed='o.money,o.order_sn,p.project_name,m.username,m.mobile';
        $res=$this->alias('o')
            ->join('project p','o.project_id=p.id')
            ->join('member m','o.uid=m.id')
            ->where($where)
            ->field($filed)
            ->select();
        return empty($res)?array():$res->toArray();
    }




}
